<template>
	<view class="select-supervisor">
		<navBar title="工程項選擇" @goBack="uni.navigateBack()"></navBar>

		<scroll-view @scrolltolower="scrolltolower" scroll-y
			:style="{height: 'calc(100vh - ' + containerOutsideHeight + 'px)'}">
			<view style="height: 100%;">
				<view class="search">
					<u-search @search="confirmSearch" @change="confirmSearch" v-model="keyWord"
						placeholder="請輸入關鍵字" :showAction="false" clearabled height="88upx" />
				</view>
				<view class="uni-container" style="padding-bottom: 20rpx;">
					<uni-table ref="table"  stripe emptyText="暫無更多數據" width="200">
						<uni-tr>
							<uni-th align="center" width="55">序號</uni-th>
							<uni-th align="center" width="55">編碼</uni-th>
							<uni-th align="center">工程項</uni-th>
						</uni-tr>
						<uni-tr v-for="(item, index) in tableData" :key="index">
							<uni-td align="center" width="55">
								<view @click="selectItem(item)" style="width: 18px;height: 18px;background: #ADC0DF;border-radius: 2px;line-height: 18px;color: #fff;margin: auto;">
									{{ index + 1 }}
								</view>
							</uni-td>
							<uni-td align="center" width="55" >
								<view  @click="selectItem(item)">
									{{ item.coding }}
								</view>
							</uni-td>
							<uni-td align="left">
								<view @click="selectItem(item)">
									{{ item.projectItem }}
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import { mapGetters } from "vuex";
	import { getSystemHeightInfo } from "@/utils/common.js";
	import { hkProjectItemsConfig_getNodeTree } from "@/api/HongKong/hkAttendanceSheet.js";	
	export default {
		name: "select-woItem",
		data() {
			return {
				keyWord:'',
				tableData: [],
				index:undefined
			}
		},
		computed: {
			...mapGetters(['dictMap'])
		},
		onLoad(options) {
			this.initContainerData();
			this.getTableData()
			const eventChannel = this.getOpenerEventChannel();
			this.eventChannel = eventChannel
			if(options && options.index) {
				this.index = options.index
				
			}

		},
		methods: {
			confirmSearch(){},
			scrolltolower(){},
			/** 初始化容器数据 */
			initContainerData() {
				const { stateHeight, bottomHeight, navbarHeight } = getSystemHeightInfo();
				this.containerOutsideHeight = stateHeight + bottomHeight + navbarHeight;
			},
			
			getTableData() {
				hkProjectItemsConfig_getNodeTree({projectId:uni.getStorageSync('isOwner')}).then(res => {
					if(res.success) {
						const treeData = res.result || []
						if(treeData.length) {
							for(let item1 of treeData) {
								item1.val = false
								item1.fileListImg = []
								if(item1.children && item1.children.length) {
									for(let item2 of item1.children) {
										for(let item3 of item2) {
											item3.value = ''
										}
									}
								}
							}
						}
						console.log(treeData, '组装的数据')
						this.tableData = treeData
					}
				})
			},
			selectItem(obj) {
				console.log(this.index, '数据')
				obj.val = true
				uni.navigateBack({
					success: () => {
						this.eventChannel.emit("getItemInfo", {
							data: obj,
							index:this.index
						})
					}
				});
			}


		}
	}
</script>

<style scoped lang="scss">
	.select-supervisor {
		font-size: 32upx;
		/* #ifdef MP-WEIXIN */
		padding-top: 200rpx;

		/* #endif */
		.search {
			padding: 42upx 36upx 14upx 28upx;
			position: sticky;
			top: 0px;
			border-top: 1px solid #fff;
			background: #fff;
			z-index: 1;
		}
	}





</style>